package algorithms;

public class Tree {
	public Element head = null;
	
	public Element min(){
		Element current = head;
		while(current.left!=null){
			current = current.left;
		}
		return current;
	}
	
	public Element max(){
		Element current = head;
		while(current.right!=null){
			current = current.right;
		}
		return current;
	}
	
	
	public void add(Element elem){
		if(head==null){
			head = elem;
		}else{
			Element current = head;
			while(true){
				if (current.key>elem.key){
					if(current.left==null){
						current.left=elem;
						return;
					}else{
						current=current.left;
					}
				}
				if (current.key<elem.key){
					if(current.right==null){
						current.right=elem;
						return;
					}else{
						current=current.right;
					}
				}
			}
		}
	}
}
